package smedi.ismedi.web.bff.controller.safetycheck;

import com.smedi.ismedi.constructionproject.api.feign.RemoteConstructionProjectFeignApi;
import com.smedi.ismedi.safetycheck.dto.request.organzaition.*;
import com.smedi.ismedi.safetycheck.dto.response.organzaition.DutyRegionResponse;
import com.smedi.ismedi.safetycheck.feign.RemoteSafetyOrganizationFeignApi;
import com.smedi.ismedi.web.starter.common.PaginationData;
import com.smedi.ismedi.web.starter.common.ResponseData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author Jimmy
 * @Date 2021/6/22 10:26
 */
@Api(tags = {"安全组织"})
@Slf4j
@RequestMapping(value = "/webbff/v1/safety-organization")
@RestController
@AllArgsConstructor
public class SafetyOrganizationController {
    private final RemoteConstructionProjectFeignApi remoteConstructionProjectFeignApi;

    private final RemoteSafetyOrganizationFeignApi remoteSafetyOrganizationFeignApi;

    @ApiOperation(httpMethod = "POST", value = "上传/重新上传区域照片")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目Id", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "regionPicture", value = "区域照片signKey", dataType = "String", dataTypeClass = Integer.class)
    })
    @PostMapping(value = "/uploadRegionPicture")
    public ResponseData<Boolean> uploadRegionPicture(Long projectId, String regionPicture) {
        remoteConstructionProjectFeignApi.postSaveRegionPicture(projectId, regionPicture);

        return new ResponseData<>().success(true);
    }

    @ApiOperation(httpMethod = "POST", value = "上传/重新上传组织机构照片")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目Id", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "organizationPicture", value = "组织机构照片signKey", dataType = "String", dataTypeClass = Integer.class)
    })
    @PostMapping(value = "/uploadOrganizationPicture")
    public ResponseData<Boolean> uploadOrganizationPicture(Long projectId, String organizationPicture) {
        remoteConstructionProjectFeignApi.postSaveOrganizationPicture(projectId, organizationPicture);

        return new ResponseData<>().success(true);
    }

    @ApiOperation(httpMethod = "POST", value = "上传/重新上传安全责任委托书")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", name = "projectId", value = "项目Id", dataType = "Long", dataTypeClass = Long.class),
            @ApiImplicitParam(paramType = "query", name = "entrustBook", value = "安全责任委托书signKey", dataType = "String", dataTypeClass = Integer.class)
    })
    @PostMapping(value = "/uploadEntrustBook")
    public ResponseData<Boolean> uploadEntrustBook(Long projectId, String entrustBook) {
        remoteConstructionProjectFeignApi.postSaveEntrustBook(projectId, entrustBook);

        return new ResponseData<>().success(true);
    }

    /**
     * 获取 责任区域 key
     *
     * @return ResponseData<String>
     */
    @ApiOperation(value = "获取 责任区域 key", nickname = "获取 责任区域 key")
    @PostMapping(value = "/getDutyRegionKey")
    ResponseData<String> getDutyRegionKey() {
        return remoteSafetyOrganizationFeignApi.getDutyRegionKey();
    }

    /**
     * 责任区域新增
     *
     * @param dutyRegionCreateRequest 责任区域新增
     * @return ResponseData<DutyRegionResponse>
     */
    @ApiOperation(value = "责任区域新增", nickname = "责任区域新增")
    @PostMapping(value = "/create")
    ResponseData<DutyRegionResponse> createDutyRegion(@Validated @RequestBody DutyRegionCreateRequest dutyRegionCreateRequest) {
        return remoteSafetyOrganizationFeignApi.createDutyRegion(dutyRegionCreateRequest);
    }

    /**
     * 责任区域编辑
     *
     * @param dutyRegionEditRequest 责任区域编辑
     * @return ResponseData<DutyRegionResponse>
     */
    @ApiOperation(value = "责任区域编辑", nickname = "责任区域编辑")
    @PostMapping(value = "/edit")
    ResponseData<DutyRegionResponse> editDutyRegion(@Validated @RequestBody DutyRegionEditRequest dutyRegionEditRequest) {
        return remoteSafetyOrganizationFeignApi.editDutyRegion(dutyRegionEditRequest);
    }

    /**
     * 获取 责任区域 单一
     *
     * @param dutyRegionOneRequest 责任区域 单一 请求
     * @return ResponseData<DutyRegionResponse>
     */
    @ApiOperation(value = "获取 责任区域 单一", nickname = "获取 责任区域 单一")
    @PostMapping(value = "/one")
    ResponseData<DutyRegionResponse> getDutyRegionOne(@Validated @RequestBody DutyRegionOneRequest dutyRegionOneRequest) {
        return remoteSafetyOrganizationFeignApi.getDutyRegionOne(dutyRegionOneRequest);
    }

    /**
     * 责任区域删除
     *
     * @param dutyRegionRemoveRequest 责任区域删除
     * @return ResponseData<DutyRegionResponse>
     */
    @ApiOperation(value = "责任区域删除", nickname = "责任区域删除")
    @PostMapping (value = "/remove")
    ResponseData<Boolean> removeDutyRegion(@Validated @RequestBody DutyRegionRemoveRequest dutyRegionRemoveRequest){
        return remoteSafetyOrganizationFeignApi.removeDutyRegion(dutyRegionRemoveRequest);
    }

    /**
     * 获取 责任区域 列表
     *
     * @param dutyRegionListRequest 责任区域 列表 请求
     * @return ResponseData<List < DutyRegionResponse>>
     */
    @ApiOperation(value = "获取 责任区域 列表", nickname = "获取 责任区域 列表")
    @PostMapping(value = "/list")
    ResponseData<List<DutyRegionResponse>> getDutyRegionList(@Validated @RequestBody DutyRegionListRequest dutyRegionListRequest) {
        return remoteSafetyOrganizationFeignApi.getDutyRegionList(dutyRegionListRequest);
    }

    /**
     * 获取 责任区域 分页
     *
     * @param dutyRegionPageRequest 责任区域 分页 请求
     * @return ResponseData<PaginationData < DutyRegionResponse>>
     */
    @ApiOperation(value = "获取 责任区域 分页", nickname = "获取 责任区域 分页")
    @PostMapping(value = "/page")
    ResponseData<PaginationData<DutyRegionResponse>> getDutyRegionPage(@Validated @RequestBody DutyRegionPageRequest dutyRegionPageRequest) {
        return remoteSafetyOrganizationFeignApi.getDutyRegionPage(dutyRegionPageRequest);
    }
}
